import { messages } from 'share/common';
import React, { Component, PropTypes } from 'react';
import { Form, Button, Row, Col } from 'antd';
import Condition from 'components/condition';
import 'styles/components/advanced-search/advanced-search.scss';

const { If } = Condition;
import AdvancedSearchFormItem from 'components/advanced-search/advanced-search-form-item';

/**
 * 因为 advanceSearch 集成了所有 搜索组件 然后 自定义报表这边的默认值 也要 实现所有能设置默认值的组件 也以对应
 * 组件打开 所以 这里不得已 copy 了下 advanceSearch 来 魔改一下。
 */
class DefaultValue extends Component {

  state = {
    collapsed: false,
    filterTags: [],
    controlledStyle: {},
    showForm: true
  };

  componentDidMount() {
    const { form, getForm, onRef } = this.props;
    getForm && getForm(form);
    onRef && onRef(this);
  }

  getFormField = field => {
    const { form } = this.props;
    return <AdvancedSearchFormItem
      form={form}
      field={field}
    />;
  };

  render() {
    const { searchForm } = this.props;
    return (
      <div className='advanced-search'>
        <Row gutter={20}>
          {searchForm.map(field => (
            <Col span={24}>
              {this.getFormField(field)}
            </Col>
          ))}
        </Row>
      </div>
    );
  }

  static propTypes = {
    searchForm: PropTypes.array,  //表单配置项，具体可见advanced-search-doc.js
    onReset: PropTypes.func,
  };

  static defaultProps = {
    searchForm: [],
    searchButton: {
      props: { type: 'primary' },
      text: messages('common.search')/*搜索*/
    },
    resetButton: messages('common.reset')/*重置*/
  };

}

export default Form.create()(DefaultValue);
